package com.hernandez.games.adventures.controllers;

import com.hernandez.games.adventures.beans.GameStatus;
import com.hernandez.games.adventures.events.ExitEvent;
import com.hernandez.games.adventures.events.GameStatusChangedEvent;
import com.hernandez.games.adventures.events.IEventHandler;

public class GameController implements IController, IEventHandler<ExitEvent> {
	public GameController() {
		EventController eventController = EventController.getInstance();
		eventController.registerHandler(ExitEvent.class, this);
		new InputController();
		new ViewController();
		CPUTickController cpuTickController = new CPUTickController();
		eventController.publishEvent(new GameStatusChangedEvent(GameStatus.PREPARING));
		eventController.publishEvent(new GameStatusChangedEvent(GameStatus.STARTED));
		eventController.publishEvent(new GameStatusChangedEvent(GameStatus.RUNNING));
		cpuTickController.run();
	}

	@Override
	public void publishEvent(ExitEvent event) {
		EventController.getInstance().publishEvent(new GameStatusChangedEvent(GameStatus.EXITING));
	}
}
